const readFile = require("../../../utils/readFile");

function readDataFileJson(req, res, next) {
  const path = req.path.replace("/api", "");
  readFile(path).then(
    (rest) => {
      res.json({
        code: 200,
        data: JSON.parse(rest),
        message: "成功",
      });
    },
    () => {
      res.json({
        code: 10000,
        data: {},
        message: "读取失败 该路径并无存在node服务",
      });
    }
  );
}

module.exports = {
  path: "/api/*",
  function: readDataFileJson,
  method: "get",
};
